<%-- 
    Document   : Shopping
    Created on : Apr 23, 2009, 9:04:54 PM
    Author     : dale

    Displays a form containing items from the store inventory
--%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<%@page contentType="text/html" pageEncoding="UTF-8" import="store.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Shopping with JSF</title>
    </head>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
        <font FACE=VERDANA></font>
        
        <center>
        <H2>Hello 
        <h:outputText id="name" value = "#{customerBean.name}" />,
        Welcome to the Store</H2>
        <H3>Please put a Quantity Beside Each Item</H3>

        <jsp:useBean id="customerBean" class="beans.Customer" scope="session" ></jsp:useBean>
        <%
          String itemNumberString = request.getParameter("itemNumber");
          int currentItemNumber = 0;
          if (itemNumberString != null) {
              currentItemNumber = Integer.parseInt(itemNumberString);
          }

          int itemsPerPage = 5;
          Integer itemsPerPageInt = (Integer) session.getAttribute("itemsPerPage");
          if (itemsPerPageInt != null) {
            itemsPerPage = itemsPerPageInt.intValue();
          }

          customerBean.setItemNumber(currentItemNumber);
          customerBean.setItemsPerPage(itemsPerPage);
        %>
        <h:form id="shoppingForm" >
        <h:dataTable id="items"
            border="1"
            captionClass="list-caption"
            columnClasses="list-column-center, list-column-left,
                list-column-right, list-column-center"
            footerClass="list-footer"
            headerClass="list-header"
            rowClasses="list-row-even, list-row-odd"
            styleClass="list-background"
            summary="Summary"
            value="#{customerBean.shopItems}"
            first="#{customerBean.itemNumber}"
            rows="#{customerBean.itemsPerPage}"
            var="item">
            <h:column headerClass="list-header-left">
                <f:facet name="header">
                    <h:outputText value="Quantity" />
                </f:facet>
                <h:inputText id="quantity" value="#{item.quantity}"
                    validatorMessage="Go Back and Enter a Valid Quantity">
                    <f:validateDoubleRange
                     minimum="0.0"
                     maximum="1000.0" />
                </h:inputText>
                <h:message
                     style="color: red;
                     font-family: ’New Century Schoolbook’, serif;
                     font-style: oblique;" id="quantityError" for="quantity"/>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Description"/>
                </f:facet>
                <h:outputText id="description" value="#{item.name}" />
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Unit"/>
                </f:facet>
                <h:outputText id="unit" value="#{item.unit}" />
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Price"/>
                </f:facet>
                <h:outputText id="price" value="#{item.price}" >
                        <f:convertNumber type="currency" />
                </h:outputText>
            </h:column>
            <f:facet name="caption">
                <h:outputText escape="false" value="<b>Our Freshest Groceries</b>"/>
            </f:facet>
        </h:dataTable>
        <input type="hidden" name="itemNumber" value="<%= currentItemNumber + itemsPerPage %>" />
        <h:commandButton id="next" action="#{customerBean.addBeansToCart}" value="Next" />
        </h:form>
        </center>
    </body>
</html>
</f:view>
